package com.gopay.webtest.controller.cloud;


import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.controller.base.BaseController;
import com.gopay.webtest.handler.cloud.TransCloudSignHandler;
import com.gopay.webtest.util.DateUtils;
import com.gopay.webtest.vo.cloud.Cloud0607Vo;
import com.gopay.webtest.vo.cloud.Cloud0608Vo;
import com.gopay.webtest.xml.XmlDao;

/**
 * 
 * boai
 * 2016年1月04日 
 * www.gopay.com.cn Inc.All rights reserved.
 */
@RequestMapping("/bindCard")
@Controller
public class BindCardController extends BaseController{
	
	@Resource(name = "xmlDao")
    private XmlDao xmlDao;
	
	@Resource(name = "transCloudSignHandler")
	private TransCloudSignHandler transCloudSignHandler;
    /**
     * 跳转到申请页面
     * 
     * @return
     */
    @RequestMapping("/chargeApply")
    public ModelAndView chargeApply() {
        ModelAndView mv = new ModelAndView();

        
        try {
        	 Map<String, String> map = xmlDao.readData4Map("cloud_apply", "bindCard");

             map.put("reqTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
             mv = new ModelAndView("cloud.charge.bindCard");
             mv.addObject("config", map);
             this.logger.info("^^^^^^^^^^^^^^^^^云平台绑卡页面初始化成功^^^^^^^^^^^^^^^^^");
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }

        return mv;
    }
    @RequestMapping("/doCharge")
    public ModelAndView doCharge(@ModelAttribute Cloud0607Vo c0607Vo){
    	 ModelAndView mv = new ModelAndView();
         mv.setViewName("cloud.charge.doBind");

         try {
             // 签名
        	 transCloudSignHandler.sign(c0607Vo.getTranCode()+"_"+c0607Vo.getVersion(), "signType", "signValue", c0607Vo, getRequest());
        	 this.logger.info("^^^^^^^^^^^^^^^^^云平台绑卡页面签名成功^^^^^^^^^^^^^^^^^");
             mv.addObject("c0607Vo", c0607Vo);
         } catch (Exception e) {
             logger.error("执行申请", e);
         }
         return mv;
    }
    /**
     * 跳转到申请页面
     * 
     * @return
     */
    @RequestMapping("/chargeApplyRemove")
    public ModelAndView chargeApplyRemove() {
        ModelAndView mv = new ModelAndView();
        try {
        	 Map<String, String> map = xmlDao.readData4Map("cloud_apply", "removeBind");

             map.put("reqTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
             mv = new ModelAndView("cloud.charge.removeBind");
             mv.addObject("config", map);
             this.logger.error("^^^^^^^^^^^^^^^^^云平台开户页面初始化成功^^^^^^^^^^^^^^^^^");
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }

        return mv;
    }    
    @RequestMapping("/doChargeRemove")
    public ModelAndView doChargeRemove(@ModelAttribute Cloud0608Vo c0608Vo){
    	 ModelAndView mv = new ModelAndView();
         mv.setViewName("cloud.charge.doRemove");

        try {
             // 签名
        	 transCloudSignHandler.sign(c0608Vo.getTranCode()+"_"+c0608Vo.getVersion(), "signType", "signValue", c0608Vo, getRequest());
        	 this.logger.error("^^^^^^^^^^^^^^^^^云平台开户页面签名成功^^^^^^^^^^^^^^^^^");

             mv.addObject("c0608Vo", c0608Vo);
         } catch (Exception e) {
             logger.error("执行申请", e);
         }
         return mv;
    }   
}
